import sys

import numpy
import tables
from matplotlib import pyplot
fp = tables.openFile(sys.argv[1])
data = fp.root.data.read()

pedestals = numpy.loadtxt(sys.argv[2])

x = []
y = []
ysub = []
for win, samp, adc in data[:64]:
    x.append(samp)
    y.append(adc)
    ysub.append(adc - pedestals[win][samp])

pyplot.subplot(211)
pyplot.plot(x, y, 'r.', label='Peds not subtracted')

pyplot.ylabel("ADC counts")
pyplot.title("Window %d Raw" % win)

pyplot.subplot(212)
pyplot.plot(x, ysub, 'b.', label='Peds subtracted')

pyplot.xlim(-1.5, 64.5)
pyplot.xlabel("Sample #")
pyplot.ylabel("ADC counts")
pyplot.title("Window %d Pedestal Subtracted" % win)
#pyplot.legend()

pyplot.savefig(sys.argv[1].rsplit('.', 1)[0] + '.png')





